<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="../templates/popup.xhtml">
	<ui:define name="titre">#{lbl['menu.hub.arrival']}</ui:define>
	<ui:define name="popup_page">

		<!-- Fonctions javascript. -->
		<script language="javascript">
			function javascriptOnLoad(){
					self.opener.refreshHub();
				}
		</script>

		<!-- La légende pour les arrivées. -->
		<ui:include src="../blocs/inc_arrival_legend.xhtml" />

		<a4j:outputPanel id="arrival_panel">
			<!-- La liste des erreurs. -->
			<rich:messages />

			<h:form id="arrival_form">
				<h:panelGrid style="width:100%;height:390px;"
					columnClasses="_left_top">
					<rich:dataTable id="arrival_table" value="#{hubManaged.lstSillons}"
						var="sillon" style="width:100%"
						rowClasses="rich_datagrid_odd_line, rich_datagrid_even_line"
						styleClass="stable" iterationStatusVar="it" rows="10">

						<f:facet name="noData">
							&nbsp;<h:outputText value="#{msg['msg.info.nodata']}"
								style="font-size:12px" />
						</f:facet>

						<rich:column style="width:40px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.id']}" />
							</f:facet>
							<h:outputText value="#{sillon.extId}" />
						</rich:column>

						<!-- On place un lien pour charger le relevé de composition. -->
						<rich:column style="width:120px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.train.id']}" />
							</f:facet>

							<!-- Uniquement si présence fichier. -->
							<h:commandLink action="#{inputDataFileManaged.downloadFile}"
								rendered="#{sillon.compositionFileName}">
								<h:outputText value="#{sillon.tcmsTrainId}"
									style="color:#000000;text-decoration: underline;" />
								<a4j:param name="fileName"
									assignTo="#{inputFileDataManaged.fileName}"
									value="#{sillon.compositionFileName}" />
							</h:commandLink>

							<!-- Si composition non chargée par fichier. -->
							<h:outputText value="#{sillon.tcmsTrainId}"
								rendered="#{!sillon.compositionFileName}" />
						</rich:column>

						<rich:column style="width:60px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.train.lading']}" />
							</f:facet>
							<h:outputText value="#{sillon.lading}" />
						</rich:column>

						<rich:column style="width:160px;text-align:left;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.origin']}" />
							</f:facet>
							<h:outputText value="#{sillon.origin}" />
						</rich:column>

						<rich:column style="width:60px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.nb.wagon']}" />
							</f:facet>
							<h:outputText value="#{sillon.nbWagons}" />
						</rich:column>

						<rich:column style="width:80px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.theo.date']}" />
							</f:facet>
							<h:outputText value="#{sillon.movementDate}">
								<f:convertDateTime pattern="dd/MM/yyyy" timeZone="Europe/Paris" />
							</h:outputText>
						</rich:column>

						<rich:column style="width:85px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.teo.time']}" />
							</f:facet>
							<h:outputText value="#{sillon.movementTime}" />
						</rich:column>

						<rich:column style="width:110px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.real.date']}" />
							</f:facet>
							<rich:calendar inputSize="10" value="#{sillon.realMovementDate}"
								todayControlMode="hidden" datePattern="dd/MM/yyyy"
								showFooter="false"
								disabled="#{sillon.statusId == 6 || sillon.statusId == 7 || sillon.statusId == 8}">
							</rich:calendar>
						</rich:column>

						<rich:column style="width:90px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.real.time']}" />
							</f:facet>
							<h:inputText value="#{sillon.realMovementTime}" size="5"
								disabled="#{sillon.statusId == 6 || sillon.statusId == 7 || sillon.statusId == 8}"
								maxlength="5" onkeypress="return checkTime(this);" />
						</rich:column>

						<rich:column style="width:90px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.sens']}" />
							</f:facet>
							<h:selectOneMenu id="reverseSense" value="#{sillon.reverseSense}"
								onchange="reverseSense(#{it.index}, this.value);"
								disabled="#{sillon.statusId == 5 || sillon.statusId == 6 || sillon.statusId == 7 
								|| sillon.statusId == 8}">
								<f:selectItem itemLabel="#{lbl['common.no']}" itemValue="false" />
								<f:selectItem itemLabel="#{lbl['common.yes']}" itemValue="true" />
							</h:selectOneMenu>
						</rich:column>

						<rich:column style="width:130px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.rail']}" />
							</f:facet>
							<h:selectOneMenu id="arrivalRailId" value="#{sillon.railId}"
								onchange="checkArrivalRail(#{it.index}, 1, this.value);"
								disabled="#{sillon.statusId == 6 || sillon.statusId == 7 || sillon.statusId == 8}">
								<f:selectItems value="#{repositoryManaged.lstAllRails}" />
							</h:selectOneMenu>
						</rich:column>

						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['common.comment']}" />
							</f:facet>
							<a4j:commandLink execute="@this" render="sillon_comment_panel"
								oncomplete="centerPopup(380, 180, 'sillon_comment_div'); 
								display_div(true,'sillon_comment_div');makeFocusOnField('arrival_form:comment');">
								<h:graphicImage value="../../imgs/icons/ico_comment.png"
									width="30" rendered="#{!sillon.commentFilled}" />

								<h:graphicImage value="../../imgs/icons/ico_comment_filled.png"
									width="30" rendered="#{sillon.commentFilled}" />
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
							</a4j:commandLink>
						</rich:column>

						<rich:column style="width:65px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival.plan']}" />
							</f:facet>

							<!-- Etat : Demande de création du plan de travail. -->
							<a4j:commandLink execute="@this"
								rendered="#{sillon.statusId == 4 || sillon.statusId == 6}"
								action="#{hubManaged.getWorkingPlan}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_plan.png" width="30" />
							</a4j:commandLink>

							<!-- Etat : Pas de plan de travail à faire (trains vides). -->
							<h:graphicImage value="../../imgs/icons/ico_plan_disabled.png"
								width="30" rendered="#{sillon.statusId == 3}" />

							<!-- Etat : Plan de travail demandé. -->
							<a4j:commandLink execute="
								@this"
								disabled="#{sillon.statusId == 5}"
								oncomplete="self.opener.refreshHub();"
								rendered="#{sillon.statusId == 7 }"
								action="#{hubManaged.processWorkingPlan}" render="arrival_panel">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_plan_request.png"
									width="30" />
							</a4j:commandLink>

							<!-- Etat : Plan de travail à demander mais train non arrivé. -->
							<h:graphicImage
								value="../../imgs/icons/ico_plan_request_disabled.png"
								width="30" rendered="#{sillon.statusId == 5}" />

							<!-- Etat : Plan de travail demandé, réalisation en cours. -->
							<a4j:commandLink execute="@this"
								rendered="#{sillon.statusId == 8}"
								oncomplete="self.opener.refreshHub();"
								action="#{hubManaged.completeWorkingPlan}"
								render="arrival_panel,arrival_form">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_plan_process.png"
									width="30" />
							</a4j:commandLink>
						</rich:column>

						<!-- Validation du train à reception. -->
						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.arrival']}" />
							</f:facet>

							<!-- Train non arrivé. -->
							<a4j:commandLink execute="@form" render="arrival_panel"
								oncomplete="self.opener.refreshHub();"
								action="#{hubManaged.completeArrival}"
								rendered="#{sillon.statusId == 3 || sillon.statusId == 4 
								|| sillon.statusId == 5}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_validate.png"
									width="25" />
							</a4j:commandLink>

							<!-- Train arrivé. -->
							<h:graphicImage
								value="../../imgs/icons/ico_validate_complete.png" width="25"
								rendered="#{sillon.statusId == 6 || sillon.statusId == 7 
								|| sillon.statusId == 8}" />
						</rich:column>

						<!-- Annulation du train à reception. -->
						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['common.delete']}" />
							</f:facet>
							<a4j:commandLink execute="@this" render="confirm_del_popup"
								oncomplete="#{rich:component('confirm_del_popup')}.show()">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_delete.png"
									width="25" />
							</a4j:commandLink>
						</rich:column>

						<f:facet name="footer">
							<rich:dataScroller page="#{hubManaged.page}" />
						</f:facet>
					</rich:dataTable>
				</h:panelGrid>

				<!-- Bouton de fermeture. -->
				<h:panelGrid style="width:100%" columnClasses="_center">
					<h:commandButton value="#{lbl['common.button.close']}"
						onclick="self.opener.releaseOneWindow();self.close();" />
				</h:panelGrid>

				<!-- Pilotage des lignes tableau. -->
				<ui:include src="../blocs/inc_selector.xhtml" />

				<!-- Panneau de saisie commentaire. -->
				<ui:include src="../blocs/inc_sillon_comment.xhtml" />

				<!-- ********************************* -->
				<!-- Popup pour la suppression sillon. -->
				<rich:popupPanel id="confirm_del_popup"
					headerClass="rich_panel_popup_head"
					header="#{lbl['sillon.confirm']}" autosized="true">
					<h:panelGrid styleClass="panel" width="460" height="90"
						id="del_panel">
						<h:panelGroup>
							<h:outputText value="#{msg['msg.confirm.sillon.delete']}" /> :  
							<h:outputText value="#{hubManaged.currentSillon.extId}" /> ?
							
							<h:panelGroup
								rendered="#{hubManaged.currentSillon.statusId == 6 
								|| hubManaged.currentSillon.statusId == 7 
								|| hubManaged.currentSillon.statusId == 8}">
								<p />
								<h:outputText value="#{msg['sillon.arrived']}"
									style="font-color:#B30503" />
							</h:panelGroup>
						</h:panelGroup>
						<h:panelGrid columns="3" columnClasses="_left, _center, _right"
							width="100%" style="margin-top:20px">
							<a4j:commandButton id="sillon_b_cancel_delete"
								value="#{lbl['common.button.cancel']}"
								onclick="#{rich:component('confirm_del_popup')}.hide(); return false;" />

							<a4j:commandButton id="sillon_b_init"
								action="#{hubManaged.initSillon}" render="arrival_panel"
								execute="@this" value="#{lbl['common.button.init']}"
								onclick="#{rich:component('confirm_del_popup')}.hide();"
								oncomplete="self.opener.refreshHub();" />

							<a4j:commandButton id="sillon_b_delete"
								action="#{hubManaged.deleteSillon}" render="arrival_panel"
								execute="@this" value="#{lbl['common.button.delete']}"
								onclick="#{rich:component('confirm_del_popup')}.hide();"
								oncomplete="self.opener.refreshHub();" />
						</h:panelGrid>
					</h:panelGrid>
				</rich:popupPanel>

				<!-- ********************************************* -->
				<!-- Méthode pour l'inversion de sens à reception. -->
				<a4j:jsFunction name="reverseSense" execute="@this" immediate="true"
					action="#{hubManaged.reverseSense}">
					<a4j:param name="idx" assignTo="#{hubManaged.criterion.idx}" />
					<a4j:param name="reverseSense"
						assignTo="#{hubManaged.criterion.reverseSense}" />
				</a4j:jsFunction>

				<!-- ************************************************ -->
				<!-- Méthode pour le contrôle de la voie à reception. -->
				<a4j:jsFunction name="checkArrivalRail" execute="@this"
					action="#{hubManaged.checkRail}">
					<a4j:param name="idx" assignTo="#{hubManaged.criterion.idx}" />
					<a4j:param name="typeCheckRail"
						assignTo="#{hubManaged.criterion.typeCheckRail}" />
					<a4j:param name="posRailId"
						assignTo="#{hubManaged.criterion.posRailId}" />
				</a4j:jsFunction>
			</h:form>
		</a4j:outputPanel>
	</ui:define>
</ui:composition>
</html>